﻿
Partial Class WebForm_SearchControl_SearchOrganizationControl
    Inherits System.Web.UI.UserControl

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub

    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
        If e.CommandName = "Select" Then
            Dim rowIndex As Integer = e.CommandArgument
            Me.SelectedOrganizationID = Me.gv.DataKeys(rowIndex)("OrganizationID")
            RaiseEvent SelectedIndexChanged(Me, New EventArgs)
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Visible = True
    End Sub

    'Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
    '    Me.BindGV()
    '    Me.mpSearch.Show()
    'End Sub
End Class

Partial Class WebForm_SearchControl_SearchOrganizationControl
    Public Sub Show()
        Me.BindGV()
    End Sub

    Private Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyOrganizationDataFilter

        sql.Length = 0
        sql.AppendFormat("select o.*, dbo.FD_GetUOrganizationID(o.OrganizationID,-1) as UOrganizationID ")
        sql.AppendFormat(" from Organization o ")
        'sql.AppendFormat("inner join FD_UserOrganizationAuth oa on o.OrganizationID = oa.OrganizationID ")
        sql.AppendFormat("where Active = 'Y' ")
        'sql.AppendFormat("and u.UserID = '{0}' ", clsAuth.GetUserID())

        sql.AppendFormat(Me.GetWhereSQL())

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()

        Me.mpSearch.Show()
    End Sub

    Public Function GetWhereSQL() As String
        Dim sql As New MyStringBuilder

        'If Me.txtVolunteerName.Text <> "" Then
        '    sql.AppendFormat("and VolunteerName like '%{0}%' ", Me.txtVolunteerName.Text)
        'End If

        Return sql.ToString()
    End Function

    Public Property SelectedOrganizationID() As String
        Get
            Return ViewState("SelectedOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("v") = value
        End Set
    End Property

    Public Property UOrganizationID() As String
        Get
            Return ViewState("UOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("UOrganizationID") = value
        End Set
    End Property


    Public Event SelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)
End Class